package com.bsy.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class Avg_yongdianliangDao {
	public Map<String,Object>  query() {
		List<String> avg_yongdianliangArr1 = new ArrayList<String>();
		List<String> avg_yongdianliangArr2 = new ArrayList<String>();	
		List<Integer> avg_yongdianliangArr3 = new ArrayList<Integer>();
		List<Integer> avg_yongdianliangArr4 = new ArrayList<Integer>();	
		List<Integer> avg_yongdianliangArr5 = new ArrayList<Integer>();
		List<Integer> avg_yongdianliangArr6 = new ArrayList<Integer>();
		List<Integer> avg_yongdianliangArr7 = new ArrayList<Integer>();
		List<Integer> avg_yongdianliangArr8 = new ArrayList<Integer>();	
		List<Integer> avg_yongdianliangArr9 = new ArrayList<Integer>();
		List<Integer> avg_yongdianliangArr10 = new ArrayList<Integer>();	
		Map<String, Object> map = new HashMap<String, Object>();
		Connection conn = null;
		Properties properties = new Properties();
		properties.setProperty("user", "root");
		properties.setProperty("password", "123456");
		properties.setProperty("useSSL", "false");
		properties.setProperty("autoReconnect", "true");

		try {
			Class.forName("com.mysql.jdbc.Driver");

		 conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bigdata_bsy?useUnicode=true&characterEncoding=utf-8",
					properties);
			PreparedStatement stmt = conn.prepareStatement("SELECT * FROM t_avg_youdianliang");
			ResultSet rs = stmt.executeQuery();
			
			while (rs.next()) {
				
				avg_yongdianliangArr1.add(rs.getString("date"));
				avg_yongdianliangArr2.add(rs.getString("yingyong"));
				avg_yongdianliangArr3.add(rs.getInt("youjian"));
				avg_yongdianliangArr4.add(rs.getInt("yingxiao"));
				avg_yongdianliangArr5.add(rs.getInt("lianmeng"));
				avg_yongdianliangArr6.add(rs.getInt("guanggao"));
				avg_yongdianliangArr7.add(rs.getInt("shipin"));
				avg_yongdianliangArr8.add(rs.getInt("zhijie"));
				avg_yongdianliangArr9.add(rs.getInt("fangwen"));
				avg_yongdianliangArr10.add(rs.getInt("sousuo"));
				
			}
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		map.put("date", avg_yongdianliangArr1);
		map.put("yingyong", avg_yongdianliangArr2);
		map.put("youjian", avg_yongdianliangArr3);
		map.put("yingxiao", avg_yongdianliangArr4);
		map.put("lianmeng", avg_yongdianliangArr5);
		map.put("guanggao", avg_yongdianliangArr6);
		map.put("shipin", avg_yongdianliangArr7);
		map.put("zhijie", avg_yongdianliangArr8);
		map.put("fangwen", avg_yongdianliangArr9);
		map.put("sousuo", avg_yongdianliangArr10);
		return map;
	}

}
